package asia.lxq.cic.service;

import asia.lxq.cic.dao.CommentMapper;
import asia.lxq.cic.dao.UserMapper;
import asia.lxq.cic.entity.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CommentService {

    @Autowired
    CommentMapper commentMapper;
    @Autowired
    UserMapper userMapper;

    public List<Comment> getCommentListByArticle(int articleId){
        List<Comment> commentList = commentMapper.selectCommentListByArticle(articleId);
        commentList.forEach(comment -> comment.query(userMapper));
        return commentList;
    }

    public void postComment(Comment comment){
        commentMapper.insert(comment);
    }
}
